package com.team.arms.exception;


import com.team.arms.common.Result;
import com.team.arms.common.Result2;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLException;
import java.sql.SQLIntegrityConstraintViolationException;


@RestControllerAdvice
public class GlobalExceptionHandler {
    @ExceptionHandler(SQLException.class)
    public Result2 sqlException(SQLException e) {
        if (e instanceof SQLIntegrityConstraintViolationException) {
            return Result2.error("该数据有关联数据，操作失败!");
        }
        return Result2.error("数据库异常，操作失败!");
    }
}
